//
//  changecarViewController.m
//  car
//
//  Created by chenxu on 15/3/19.
//  Copyright (c) 2015年 chenxu. All rights reserved.
//

#import "changecarViewController.h"

@interface changecarViewController ()

@end

@implementation changecarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    carview = [[CarView alloc]initWithFrame:CGRectMake(0, 0, kScreen_Width, self.view.frame.size.height) car:_car];
    carview.myTableView.tableFooterView = [self tableFooterView];
    [self.view addSubview:carview];

}

- (UIView*)tableFooterView{
    UIView *footerV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreen_Width, 90)];
    CGFloat btnHeight = 35;
    CGFloat padding = 30;
    CGFloat btnWidth = kScreen_Width - padding*2;
    UIButton *saveBtn = [UIButton buttonWithStyle:StrapThemeStyle andTitle:@"保存" andFrame:CGRectMake(padding, 10, btnWidth, btnHeight) target:self action:@selector(save:)];
    
    UIButton *delBtn = [UIButton buttonWithStyle:StrapWarningStyle andTitle:@"删除" andFrame:CGRectMake(padding, 20+btnHeight, btnWidth, btnHeight) target:self action:@selector(deletecar:)];
    
    [saveBtn setPopingPressed];
    [delBtn setPopingPressed];
    [footerV addSubview:saveBtn];
    [footerV addSubview:delBtn];
    return footerV;
}

- (void)save:(id)sender {
    [carview modifycar:^{
        //保存成功返回上一页
        NSInteger count = [self.navigationController.viewControllers count];
        [self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:count-2] animated:YES ];
    }];
}

- (void)deletecar:(id)sender {
    [carview deletecar:^{
        //删除成功返回上一页
        NSInteger count = [self.navigationController.viewControllers count];
        [self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:count-2] animated:YES ];

    }];
}


@end
